﻿var targetNode = document.getElementsByClassName("webcast-chatroom___items")[0].children[0];
var options = { attributes: false, childList: true, subtree: false, attributeOldValue: false };
function callback(mutationsList, observer) {
    console.log(mutationsList);
    if (mutationsList[mutationsList.length - 1].addedNodes.length > 0) {
        console.log(mutationsList[mutationsList.length - 1].addedNodes[0].innerText);
    };
	if (mutationsList[mutationsList.length - 1].addedNodes.length > 0) {
		window.chrome.webview.postMessage('info' + mutationsList[mutationsList.length - 1].addedNodes[0].innerText + '$' + mutationsList[mutationsList.length - 1].addedNodes[0].innerHTML+'$' + mutationsList[mutationsList.length - 1].addedNodes[0].dataset.id);
    };
};
var mutationObserver = new MutationObserver(callback);
mutationObserver.observe(targetNode, options);

var options = { attributes: false, childList: true, subtree: true, attributeOldValue: false };
//左1
var targetNode2 = document.getElementsByClassName('ijt3p__s')[0];
function callback2(mutationsList, observer) {
	console.log('左1'); console.log(mutationsList);
	var liwu = 'liwu'; var html='';
	for (var i = 0; i < mutationsList.length; i++) {
		if (mutationsList[i].addedNodes.length>0) {
			liwu = liwu + mutationsList[i].addedNodes[0].innerText;
			html = html + mutationsList[i].addedNodes[0].innerHTML;
		}
	}
	if (mutationsList.length > 0) {
		if (liwu !='liwu') {
			console.log(liwu);
			window.chrome.webview.postMessage('liwu' + liwu + '$' + html);
		}
	}
};
var mutationObserver2 = new MutationObserver(callback2);
mutationObserver2.observe(targetNode2, options);
//左2
var targetNode3 = document.getElementsByClassName('ijt3p__s')[1];
function callback3(mutationsList, observer) {
	console.log('左2'); console.log(mutationsList);
	var liwu = 'liwu'; var html = '';
	for (var i = 0; i < mutationsList.length; i++) {
		if (mutationsList[i].addedNodes.length > 0) {
			liwu = liwu + mutationsList[i].addedNodes[0].innerText;
			html = html + mutationsList[i].addedNodes[0].innerHTML;
		}
	}
	if (mutationsList.length > 0) {
		if (liwu != 'liwu') {
			console.log(liwu);
			window.chrome.webview.postMessage('liwu' + liwu + '$' + html);
		}
	}
};
var mutationObserver3 = new MutationObserver(callback3);
mutationObserver3.observe(targetNode3, options);